#ifndef shader_directx9_h__
#define shader_directx9_h__
#include <d3dx9.h>
#include "../ishader.h"

namespace gecko
{

// forward declare types
class Renderer_DirectX9;

// DirectX 9 implementation of shader.
class Shader_DirectX9 : public IShader
{
public:
	// destructor
	virtual ~Shader_DirectX9();

	// Bind a parameter name in the shader file to an indexed parameter
	bool BindParameter(unsigned int parameter, const char* parameterName);

	// SetTechnique
	void SetTechnique(const char* techName);

	// Set the shader as begin rendering
	void Begin();

	// Finish the rendering of the shader
	void End();

	// Begin a numbered pass (use GetNumPasses before this)
	void BeginPass(unsigned int pass);

	// End the current rendering pass
	void EndPass();

	// Commit changes to the shader
	void Commit();

	// Set a matrix shader parameter
	void SetMatrix(unsigned int parameter, const Matrix44& m);

	// Set a vector shader parameter
	void SetVector(unsigned int parameter, const Vector3f& v);

	// Set an int shader parameter
	void SetInt(unsigned int parameter, int i);

	// Set a bool shader parameter
	void SetBool(unsigned int parameter, bool b);

	// Set a float shader parameter
	void SetFloat(unsigned int parameter, float f);

	// Set a blend mode shader parameter
	void SetBlendMode(unsigned int parameter, IRenderer::eBlendMode b);

	// Set a texture shader parameter
	//void SetTexture(unsigned int parameter, Texture* texture);

	// Set a colour shader parameter
	void SetColour(unsigned int parameter, const Colour& colour);

	// Serialise the shader in from a file
	bool Serialise(IRenderer* r, const char* filename);

	// Release the shader resources
	void Destroy();

	// Respond to lost device event
	bool OnLostDevice();

	// Respond to renderer reset
	bool OnResetDevice();

protected:
	// do parameter index fixup
	void PostSerialise();

private:
	// private constructor
	Shader_DirectX9(unsigned int numParameters);

	Renderer_DirectX9*  m_renderer;
	LPD3DXEFFECT m_Effect;
	D3DXHANDLE* m_Parameters;

	// allow renderer to new this up
	friend class Renderer_DirectX9;
};

}// namespace gecko

#endif // shader_directx9_h__